import {
  isNull,
  isNumber,
  isObject,
  isString,
  isArray,
  isSymbol
} from "@/unit/tool";

const columns = [
  {
    title: "订单类型",
    fixed: "left",
    width: "150px",
    // dataIndex: "orderType",
    // key: "orderType",
    ellipsis: true,
    class: "bill-order",
    scopedSlots: { customRender: "afterSaleNumber" }
  },
  {
    title: "订单编号",
    fixed: "left",
    dataIndex: "repairList.repairOrderNumber",
    // key: "repairList.repairOrderNumber",
    width: "150px",
    ellipsis: true
  },
  {
    title: "客户单位",
    dataIndex: "repairList.companyName",
    // key: "repairList.companyName",
    width: "220px",
    ellipsis: true
  },
  {
    title: "故障描述",
    dataIndex: "repairList.description",
    // key: "repairList.description",
    width: "250px",
    ellipsis: true,
    class: "fault-description"
  },
  {
    title: "报修时间",
    dataIndex: "repairList.uploadTime",
    // key: "repairList.uploadTime",
    width: "180px",
    ellipsis: true
  },
  {
    title: "订单状态",
    dataIndex: "repairList.state",
    // key: "repairList.state",
    width: "150px",
    class: "bill-state",
    ellipsis: true,
    scopedSlots: { customRender: "state" }
  },
  {
    title: "当前处理人",
    dataIndex: "appointor",
    // key: "appointor",
    width: "150px",
    ellipsis: true
  },
  {
    title: "报修人姓名",
    dataIndex: "repairList.repairman",
    // key: "repairList.repairman",
    width: "180px",
    ellipsis: true
  },
  {
    title: "报修人电话",
    dataIndex: "repairList.phoneNumber",
    // key: "repairList.phoneNumber",
    width: "150px",
    ellipsis: true
  },
  {
    title: "机床型号",
    dataIndex: "repairList.macType",
    // key: "repairList.macType",
    width: "240px",
    ellipsis: true
  },
  {
    title: "机床编号",
    dataIndex: "repairList.macNumb",
    // key: " repairList.macNumb",
    width: "240px",
    ellipsis: true
  },
  {
    title: "机床厂家",
    dataIndex: "repairList.macFactory",
    // key: "repairList.macFactory",
    width: "180px",
    ellipsis: true
  },
  {
    title: "设备购买时间",
    dataIndex: "repairList.purchaseTime",
    // key: "repairList.purchaseTime",
    width: "180px",
    ellipsis: true
  },
  {
    title: "系统型号",
    dataIndex: "repairList.ncSystemType",
    // key: "repairList.ncSystemType",
    width: "180px",
    class: "hello",
    ellipsis: true
  },
  {
    title: "所属片区",
    dataIndex: "afterSaleService.secondDepartment",
    // key: "afterSaleService.ownDistrict",
    width: "180px",
    ellipsis: true
  },
  {
    title: "任务类别",
    dataIndex: "afterSaleService.taskType",
    // key: "afterSaleService.taskType",
    width: "180px",
    ellipsis: true
  },
  {
    title: "设备类型",
    dataIndex: "afterSaleService.equipmentType",
    // key: "afterSaleService.equipmentType",
    width: "180px",
    ellipsis: true
  },
  {
    title: "保修状态",
    dataIndex: "afterSaleService.guaranteeState",
    // key: "afterSaleService.guaranteeState",
    width: "180px",
    ellipsis: true
  },
  {
    title: "客户类型",
    dataIndex: "afterSaleService.customerType",
    // key: "afterSaleService.customerType",
    width: "180px",
    ellipsis: true
  },
  {
    title: "信息来源",
    dataIndex: "afterSaleService.informationSource",
    // key: "afterSaleService.informationSource",
    class: "hello",
    width: "180px",
    ellipsis: true
  },
  {
    title: "数控系统编号",
    dataIndex: "afterSaleService.ncNumber",
    // key: "afterSaleService.ncNumber",
    width: "180px",
    ellipsis: true
  },
  {
    title: "数控系统SN",
    dataIndex: "afterSaleService.macSn",
    // key: "afterSaleService.macSn",
    width: "180px",
    ellipsis: true
  },

  {
    title: "故障发生时间",
    dataIndex: "afterSaleService.impedimentStartTime",
    // key: "afterSaleService.impedimentStartTime",
    width: "180px"
  },
  {
    title: "故障类型",
    dataIndex: "afterSaleService.impedimentType",
    // key: "afterSaleService.impedimentType",
    width: "180px",
    ellipsis: true
  },
  {
    title: "现场服务工程师",
    dataIndex: "afterSaleService.fieldEngineer",
    // key: "afterSaleService.fieldEngineer",
    width: "150px",
    ellipsis: true
  },
  {
    title: "需求建议",
    dataIndex: "afterSaleService.demandSuggestion",
    // key: "afterSaleService.demandSuggestion",
    width: "180px",
    ellipsis: true
  },
  {
    title: "其他描述",
    dataIndex: "afterSaleService.otherDescription",
    // key: "afterSaleService.otherDescription",
    width: "180px",
    ellipsis: true
  },
  {
    title: "解决方案",
    dataIndex: "afterSaleService.solution",
    // key: "afterSaleService.solution",
    width: "150px",
    ellipsis: true
  },
  {
    title: "重大专项课题名称",
    dataIndex: "afterSaleService.topicName",
    // key: "afterSaleService.topicName",
    width: "200px",
    ellipsis: true
  },
  {
    title: "重大专项课题编号",
    dataIndex: "afterSaleService.topicNumber",
    // key: "afterSaleService.topicNumber",
    width: "200px",
    ellipsis: true
  },
  {
    title: "重大专项应用领域",
    dataIndex: "afterSaleService.applicationRange",
    // key: "afterSaleService.applicationRange",
    width: "200px",
    ellipsis: true
  },
  {
    title: "服务满意度",
    dataIndex: "evaluation.serviceScore",
    // key: "evaluation.serviceScore",
    width: "150px",
    customRender: (text, row, index) => {
      return text + "分";
    }
  },
  {
    title: "服务回访备注",
    dataIndex: "evaluation.serviceEvaluate",
    // key: "evaluation.serviceEvaluate",
    width: "150px",
    ellipsis: true
  },
  {
    title: "产品满意度",
    dataIndex: "evaluation.produceScore",
    // key: "evaluation.produceScore",
    width: "150px",
    customRender: (text, row, index) => {
      return text + "分";
    }
  },
  {
    title: "产品回访备注",
    dataIndex: "evaluation.produceEvaluate",
    // key: "evaluation.produceEvaluate",
    width: "150px",
    ellipsis: true
  }
];

function buildTableData(lists) {
  // let { afterSaleService, appointor, evaluation, repairList, suit } = res;
  let newLists = [];
  lists.forEach((item, index) => {
    newLists.push(buildListsData(item, index));
  });
  return newLists;
}

function buildListsData(item, index) {
  let newRes = { key: index };
  for (let key in item) {
    if (Object.hasOwnProperty.call(item, key)) {
      let obj = item[key];
      if (!isNull(obj)) {
        newRes = Object.assign(newRes, resolveParams(obj, key));
      }
    }
  }
  return newRes;
}

function resolveParams(val, key) {
  if (isNumber(val)) {
    return { [key]: val };
  } else if (isString(val)) {
    return { [key]: val };
  } else if (isArray(val)) {
    return { [key]: val };
  } else if (isObject(val)) {
    let { id, ...restVal } = val;
    return { ...restVal };
  }
}

export { columns, buildTableData };
